<?php
/**
* @package   auto_occasion
* @subpackage commun
* @author    CMS
* @copyright 2011
* @license    All rights reserved
*/

class photoCtrl extends jController {

    public $pluginParams = array('*'=>array('auth.required'=>false
                                )
                    );
     


    /**
    * Uploader une image dans ajout annonce
    */
    function upload() {

        $rep = $this->getResponse('json');
        $rep->menusActifs = "" ;

        //jClasses::inc('commun~photoSrv');

        $ret = "error";

        try {
            jClasses::inc('commun~uploader');
            // ------------------------
            $file = $_SESSION['file'];
            $file = unserialize($file);
            $uploader = new uploader();
            // upload dans /media/original
            $uploader->source = $file;
            $uploader->destDir = PHOTO_ANNONCE_TMP_PATH;
            $uploader->upload();

            // resize - miniature
            $uploader->newWidth  = PHOTO_ANNONCE_MINIATURE_WIDTH; // in Pexels.
            $uploader->newHeight = PHOTO_ANNONCE_MINIATURE_HEIGHT;
            $uploader->resizeDir = PHOTO_ANNONCE_MINIATURE_PATH;
            $uploader->resize();

            // resize - normal
            $uploader->newWidth  = PHOTO_ANNONCE_WIDTH; // in Pexels.
            $uploader->newHeight = PHOTO_ANNONCE_HEIGHT;
            $uploader->resizeDir = PHOTO_ANNONCE_PATH;
            $uploader->resize();

            $ret = "success"; 


        } catch (exception $e) {
            die($e->getMessage());
        }

        // --------------------------------------
        $rep->data = (string)$ret;
        return $rep;
    }

}